<?php
class PlaceController extends Controller
{
	public function actionGetPhotos()
	{
		try {
			if(!isset($_GET['place_id'])){ throw new PlatwoException(9999, 'Need property gallery_id'); }
			$site = Site::model()->findByPk($_GET['place_id']);
			if($site == null){ throw new PlatwoException(9999, 'Album not found'); }
			$photos = Photo::model()->findAllByAttributes(array('photo_group'=> $site->photo_group), array("order"=> "seq"));
			$resp = array();
			foreach($photos as $key => $photo) {
				$buffer = $photo->getAttributes();
				$likeGroup = LikeGroup::model()->findByPk($photo->like_id);
				$commentGroup = CommentGroup::model()->findByPk($photo->comment_group);
				$buffer['like_count'] = ($likeGroup == null) ? 0: $likeGroup->like_count;
				$buffer['comment_count'] = ($commentGroup == null) ? 0: $commentGroup->comment_count;
				$resp[] = $buffer;
			}
			echo CJSON::encode($resp);
		} catch(PlatwoException $e) {
			echo $e->toJSON();
		}
	}
	
	public function actionPostReview()
	{
		$transaction = Yii::app()->db->beginTransaction();
		$pathImg = array();
		try {
			if(!isset($_POST['score'], $_POST['text'])) {
				throw new PlatwoException(9999, "Need parameters score, text");
			}
			$transaction->commit();
		} catch(PlatwoException $e) {
			
		}
	}
	
	public function actionTest()
	{
		//$cookie = new CHttpCookie('a', 'aaa');
		//Yii::app()->request->cookies[$cookie->name] = $cookie;
		echo Yii::app()->request->cookies['a']->value;
	}
}